# CREATE TABLE `t_ups_monitor` (
# `id` bigint DEFAULT NULL,
# `update_time` varchar(20) DEFAULT NULL,
# `ac_status` int DEFAULT NULL COMMENT '市电状态,1：市电正常 ，0：市电异常',
# `battery_status` int DEFAULT NULL COMMENT '电池充电状态,1：充电状态，0：放电状态',
# `ups_load` int DEFAULT NULL COMMENT 'UPS负载状态,1：负载过载，0：负载正常',
# `delay_time` int DEFAULT NULL COMMENT '电池后备时间,整型，单位秒',
# `battery_cap` int DEFAULT NULL COMMENT '电池剩余容量,0-100',
# `model` int DEFAULT NULL COMMENT '当前机器模式,0：无输出模式 ； 1：市电模式； 2：电池模式为； 5：自动旁路； 6：手动旁路；7： 高效模式；',
# `load_status` int DEFAULT NULL COMMENT '负载百分比,0-100%',
# `battery_voltage` int DEFAULT NULL COMMENT '电池电压, 单位v',
# `ac_frequency` int DEFAULT NULL COMMENT '输入市电频率值, 单位Hz',
# `ac_voltage` int DEFAULT NULL COMMENT '输入市电电压值, 单位v',
# `output_watt` int DEFAULT NULL COMMENT '输出Watt值, 单位Watt',
# `output_va` int DEFAULT NULL COMMENT '输出VA 值, 单位VA',
# `output_current` int DEFAULT NULL COMMENT '输出电流,单位A',
# `output_efficiency` int DEFAULT NULL COMMENT '输出效率, 0-100%',
# `output_frequency` int DEFAULT NULL COMMENT '输出频率, 单位Hz',
# `power_factor` int DEFAULT NULL COMMENT '功率因数, 0-100%',
# `output_voltage` int DEFAULT NULL COMMENT '输出电压值, 单位v'
# ) ENGINE=InnoDB DEFAULT CHARSET=utf8
import random
import time


def main():
    ac_status = 1

    battery_status = 1
    ups_load = 0
    delay_time = 60 * 6
    battery_cap = 10.0000
    model = 1
    load_status = 0
    battery_voltage = 220.000
    ac_frequency = 50
    ac_voltage = 220.000
    output_va = 220.000
    output_current = 3
    output_watt = ac_voltage * output_va

    output_efficiency = 94.000
    output_frequency = 60
    power_factor = 92
    output_voltage = 220

    start_time = "2021-04-25 09:25:41"
    strptime = time.strptime(start_time, "%Y-%m-%d %H:%M:%S")
    mktime = int(time.mktime(strptime))
    print(mktime)
    for i in range(3600 * 11):
        mktime = mktime + 1
        time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(mktime))
        if i < (8 * 3600):
            ac_status = 1
            battery_status = 1
            ups_load = 0
            if delay_time < 3600:
                delay_time = delay_time + 0.5
            if battery_cap < 100:
                battery_cap = battery_cap + 0.0125
            model = 1
            load_status = 0
            battery_voltage = 220
            ac_frequency = 50 + random.randint(0, 5)
            ac_voltage = 220
            output_va = 220
            output_current = 3 + random.uniform(0, 0.5)
            output_watt = output_current * output_va

            output_efficiency = 94 + random.uniform(0, 0.5)
            output_frequency = 50 + random.randint(0, 5)
            power_factor = 80 + random.randint(0, 9)
            output_voltage = 220
            # if 6 * 3600 <= i < 8 * 3600:
                # print("('%s', %d, %d, %d, %.2f, %.4f, "
                #       "%d, %d, %d, %d, %.2f, "
                #       "%d, %d, %.2f, %.2f, %d, %d, %d),"
                #       % (time_str, ac_status, battery_status, ups_load, delay_time, battery_cap,
                #          model, load_status, battery_voltage, ac_frequency, ac_voltage,
                #          output_watt, output_va, output_current, output_efficiency, output_frequency,
                #          power_factor,
                #          output_voltage)
                #       )
        elif 8 * 3600 <= i < 9 * 3600:
            ac_status = 0
            battery_status = 0
            ups_load = 0
            delay_time = delay_time - 0.5
            battery_cap = battery_cap - 0.0125
            model = 2
            load_status = 70 + random.randint(0, 20)
            battery_voltage = 220
            ac_frequency = 0
            ac_voltage = 0
            output_va = 220
            output_current = 3 + random.uniform(0, 0.5)
            output_watt = output_current * output_va

            output_efficiency = 94 + random.uniform(0, 0.5)
            output_frequency = 50 + random.randint(0, 5)
            power_factor = 80 + random.randint(0, 9)
            output_voltage = 220

            print("('%s', %d, %d, %d, %.2f, %.4f, "
                  "%d, %d, %d, %d, %.2f, "
                  "%d, %d, %.2f, %.2f, %d, %d, %d),"
                  % (time_str, ac_status, battery_status, ups_load, delay_time, battery_cap,
                     model, load_status, battery_voltage, ac_frequency, ac_voltage,
                     output_watt, output_va, output_current, output_efficiency, output_frequency,
                     power_factor,
                     output_voltage))
        else:
            break


def test():
    print(random.uniform(0, 0.1))


if __name__ == '__main__':
    # test()
    main()
